#include <iostream>
#include <memory>
#include <string>

using namespace std;

/*
\ brief:  商业服务
\ author: 清晨与猫鱼
*/
class BusinessService {
public:
    virtual void doProcessing() = 0;
};


/*
\ brief:  EJB服务
\ author: 清晨与猫鱼
*/
class EJBService 
    : public BusinessService {
public:
    void doProcessing() {
        cout << "Processing task by invoking EJB Service" << endl;
    }
};


/*
\ brief:  JMS服务
\ author: 清晨与猫鱼
*/
class JMSService 
    : public BusinessService {
public:
    void doProcessing() {
        cout << "Processing task by invoking JMS Service" << endl;
    }
};


/*
\ brief:  业务查找
\ author: 清晨与猫鱼
*/
class BusinessLookUp {
public:
    BusinessService* getBusinessService(string serviceType) {
        if (serviceType == "EJB") {
            return new EJBService;
        }

        return new JMSService;
    }
};


/*
\ brief:  业务代表
\ author: 清晨与猫鱼
*/
class BusinessDelegate {
public:
    void setServiceType(string serviceType) {
        serviceType_ = move(serviceType);
    }

    void doTask() {
        BusinessService* businessService = lookupService_.getBusinessService(serviceType_);
        businessService_.reset(businessService);
        businessService_->doProcessing();
    }
private:
    BusinessLookUp lookupService_;
    unique_ptr<BusinessService> businessService_;
    string serviceType_;
};


/*
\ brief:  客户端
\ author: 清晨与猫鱼
*/
class Client {
public:
    explicit Client(BusinessDelegate* businessService)
        : businessService_(businessService) {            
    }

    void doTask() {
        businessService_->doTask();
    }
private:
    unique_ptr<BusinessDelegate> businessService_;
};